<<<<<<< HEAD
(function(my){
	if(!User) {
		console.log('missing include ServerActions.js for class User');
		return;
	}
	
	my.User.prototype.__defineSetter__('uID', function(val){
		log = 'set uID:' + val;
		tool.cookie('userid', val);
	})
	my.User.prototype.__defineGetter__('uID', function(){
		var cookie = tool.cookie('userid');
		if(cookie == undefined) tool.cookie('userid', 0);
		return cookie.toString();
	})
	my.User.prototype.sessionID = 0;
	
	my.User.prototype.register = function(funcCallback){		
		my.server.request(new ActionRegister, function(data){
			if(data.errorCode)
			{
				
			}
			funcCallback(data);
		});
	}
	my.User.prototype.unregister = function(password){
		log = 'user call unregister';
	}
	my.User.prototype.login = function(password, func){
		// session should have valid value after login
		log = 'user call login [Phone:' + this.Phone + ' password:' + password + ']';
		this.pwd = password;
		var tmpthis = this;
		server.request(new ActionLogin, function(data){
			tool.error(data);
			user.uID = data.iD;
			user.pwd = undefined;
			tmpthis.getuserbaseinfo(func);
		});
	}
	my.User.prototype.getuserbaseinfo = function(func){
		var tmpthis = this;
		server.request(new ActionGetUserBaseInfo, function(data){
			for(var k in tmpthis.validkey)
			{
				var newKey = tmpthis.validkey[k];
				if(data[newKey||k] != undefined)
					tmpthis[k] = data[newKey||k];
			}
			if(func) func(tmpthis);
		});	
	};
	
	my.User.prototype.logout = function(){
		log = 'user call logout';
	}
	my.User.prototype.init = function(){
		// get cookie
		log = 'init';
		var tmpthis = this;
		if(this.uID)
		{
			log = 'userid:' + this.uID;
			this.getuserbaseinfo();		
		}else
			this.uID = 0;
	}
	my.User.prototype.validkey ={
		Phone:'phone',
		UserName:'username',
		IDCard:'iDCard',
		Level:'level',
		OwingComment:'owingComment',
		OwingMoney:'OwingMoney',
		WillBePartC:'willBePartC',
		CardCode:'cardCode',
		uID:undefined
	};
	my.user = new User
	
	my.user.init();
=======
(function (my) {
    if (!User) {
        console.log('missing include ServerActions.js for class User');
        return;
    }

    my.User.prototype.__defineSetter__('uID', function (val) {
        log = 'set uID:' + val;
        tool.cookie('userid', val);
    })
    my.User.prototype.__defineGetter__('uID', function () {
        var cookie = tool.cookie('userid');
        if (cookie == undefined)
            tool.cookie('userid', 0);
        return cookie.toString();
    })
    my.User.prototype.sessionID = 0;

    my.User.prototype.register = function (funcCallback) {
        var tmpthis = this;
        my.server.request(new ActionRegister, function (data) {
            switch (data.errorCode)
            {
                case 1:
                    tmpthis.uID = data.iD;
                    break;
                case 2:
                default:
                    log = "errorCode=" + data.errorCode;                 
            }
            
            if(funcCallback)
                funcCallback(data.errorCode, data);
        });
    }
    my.User.prototype.unregister = function (password) {
        log = 'user call unregister does not impl';
    }
    my.User.prototype.login = function (func) {
        // session should have valid value after login
        
        var tmpthis = this;
        server.request(new ActionLogin, function (data) {
            tool.error(data);
            user.uID = data.iD;
            user.pwd = undefined;
            if(func)
                func(data.errorCode, data);
        });
    }
    my.User.prototype.getuserbaseinfo = function (func) {
        var tmpthis = this;
        server.request(new ActionGetUserBaseInfo, function (data) {
            // log = "getuserbaseinfo";    
            // log = data;
            for (var k in tmpthis.validkey)
            {
                var newKey = tmpthis.validkey[k];
                // log = 'key:' + k + ' -> ' + newKey; 
                // log = 'val:' + data[newKey];
                if (data[newKey || k] != undefined)
                    tmpthis[k] = data[newKey || k];
                else
                {
                    log = newKey || k + ' -- data:undefined.';
                }
            }
            if (func)
                func(data.errorCode, tmpthis);
        });
    };

    my.User.prototype.logout = function () {
        log = 'user call logout';
    }
    my.User.prototype.init = function () {
        // get cookie
        log = 'init';
        var tmpthis = this;
        if (this.uID)
        {
            log = 'userid:' + this.uID;
            this.getuserbaseinfo(function (data) {
                log = data;
            });
        } else
            this.uID = 0;
    }
    my.User.prototype.validkey = {
        Phone: 'phone',
        UserName: 'userName',
        IDCard: 'iDCard',
        Level: 'level',
        OwingComment: 'owingComment',
        OwingMoney: 'owingMoney',
        WillBePartC: 'willBePartC',
        CarCode: 'carCode',
        uID: undefined
    };
    my.User.prototype.addCarCode = function(carCode, func){
        this.CarCode = carCode;
        var tmpthis = this;
        server.request(new ActionSetCarCode, function(data){
            if (func)
                func(data.errorCode, data);
        });
    };
    my.User.prototype.removeCarCode = function(carCode, func){
        this.CarCode = carCode;
        var tmpthis = this;
        server.request(new ActionDelCarCode, function(data){
            if (func)
                func(data.errorCode, data);
        });
    };
     my.User.prototype.setPwd = function(pwd, func){
        this.pwd = pwd;
        var tmpthis = this;
        server.request(new ActionSetPwd, function(data){
            if (func)
                func(data.errorCode, data);
        });
    };
    my.User.prototype.setBePartC = function(be, func){
        this.WillBePartC = be;
        var tmpthis = this;
        server.request(new ActionSetWillBePartC, function(data){
            if (func)
                func(data.errorCode, data);
        });
    };
    // GetDoingTaskForC
    // GetAllRentParkingSpaceInfo
    // GetParkingSpaceInfoList
    // GetPartBCOrders
    // GetPartBOrders
    // GetPartCOrders
    // GetTodoForC
    // GetTotalIncome
    
   
    my.User.prototype.queryInfo = function(id, func){       
        var tmpthis = this;
        server.request(eval('new Action' + this.query[id]), function(data){
            if (func)
                func(data.errorCode, data);
        });
    };
    my.User.prototype.query = "GetDoingTaskForC,GetAllRentParkingSpaceInfo,\
GetParkingSpaceInfoList,GetPartBCOrders,\
GetPartBOrders,GetPartCOrders,GetTodoForC,GetTotalIncome".split(',');
    for(var k in my.User.prototype.query)
    {
            my.User.prototype[my.User.prototype.query[k]] = k;
    }
    
    my.user = new User();
>>>>>>> 8f1ea022b5713246e82c62242592626f70c398ab
})(this);